﻿@{
    ViewBag.Title = "TestEntryItemList";
    Layout = "~/Views/Shared/_Layout.Test.cshtml";
}


<div id="test1">
    <div class="header">
        <div class="caption" ></div>
    </div>
    <div class="entryList"></div>
</div>

<div id="test3">
    <div class="entryList" ></div>
</div>



@CoffeeScripts.Render("~/CoffeeScripts/shared/coffee")       
@CoffeeScripts.Render("~/CoffeeScripts/models/coffee")
@CoffeeScripts.Render("~/CoffeeScripts/controllers/coffee")

<script type="text/x-jquery-tmpl" id="entryItemTemplate">
  <a href="#" rel="external" class="changePath">
     <image class="ul-li-icon" src="${links.typeInfo.url}?rel=smallIcon" />${label}
 </a>
</script>

<script type="text/coffeescript">
_file1path = "/CoffeeScripts/tests/data/json/1.txt"
_arch1path = "/CoffeeScripts/tests/data/json/3.txt"
_dir1path = "/CoffeeScripts/tests/data/json/2.txt"
_elist1path = "/CoffeeScripts/tests/data/json/list.txt"
_elist1page1path = "/CoffeeScripts/tests/data/json/listPage1.txt";
_elist1page2path = "/CoffeeScripts/tests/data/json/listPage2.txt";

asyncTest( "Parse entry list using EntryItemList", () ->  
  $(document).ready(() ->   
      _eilist1 = new Cofe.EntryItemList({
        el : $("#test1")      
      })
            
      _eilist1.childTag = "font"
      console.log(_eilist1)

      _eilist1.bind("fetchFailed", (eList) =>
         ok(false, "EntryItemList load failed"))

      _eilist1.bind("refreshed", (eilist) => 

          find1 = eilist.findAll((e) -> false)    
          find2 = eilist.findAll((e) -> true)
          find3 = eilist.find("3") #id 
          find4 = eilist.find("test1.txt") #label 
          
          ok(find1.length == 0, "FindAll(false) should return empty array")
          ok(find2.length == eilist.entryItems.length, "FindAll(true) should return all items")
          ok(find3.entry.id == "3", "Find(3) should item with id = 3")
          ok(find4.entry.label == "test1.txt", "Find(test1.txt) should return item with label = test1.txt")
          
       )    

       _eilist1.changePath(_elist1path)
       start()
  )
)

asyncTest( "Parse entry list using EntryItemList with invalid path", () ->  

    _eilist1 = new Cofe.EntryItemList()      
    _eilist1.bind("fetchFailed", (eiList, errorStr) =>         
         ok(true, "fetchFailed raised")         
         #ok("Not Found" == errorStr, "errorStr equal to Not Found")

    )

    _eilist1.bind("fetchSuccess", (eiList) =>
         ok(false, "Shouldn't reach here")
    )

    _eilist1.changePath("/abc123")    
  
    start()
    #expect(2)
)

asyncTest( "Parse paginated entry list using EntryListVIew", () ->  
  $(document).ready(() ->   
      _eilist3 = new Cofe.EntryListVIew({
        el : $("#test3")      
      })
      
      _eilist3.childTag = "font"

      _eilist3.bind("fetchFailed", (eList) =>
         ok(false, "EntryItemList load failed"))

      _eilist3.bind("refreshed", (eilist) => 

          ok(eilist.hasNextPage(), "HasNextPage")          
          ok(!eilist.hasPrevPage(), "HasPrevPage")
          console.log(eilist.getNextPage())
       )    

       #_eilist3.bind("itemClicked", (item) =>
       #    console.log("clicked")           
       #    _eilist3.goNextPage()
       #)
       
       _eilist3.changePath(_elist1page1path)
       start()
  )
)
</script>
